package cn.iocoder.yudao.module.xiaoBizHandler.service.codegen.newInner.yudao.template.java.convert;

import cn.iocoder.yudao.framework.common.genCode.common.StringBuilderHandler;
import cn.iocoder.yudao.module.xiaoBizHandler.dal.dataobject.codegen.XiaoBizHandlerCodegenColumnDO;
import cn.iocoder.yudao.module.xiaoBizHandler.dal.dataobject.codegen.XiaoBizHandlerCodegenTableDO;
import cn.iocoder.yudao.module.xiaoBizHandler.service.codegen.newInner.yudao.handler.PathHandler;
import cn.iocoder.yudao.module.xiaoBizHandler.service.codegen.newInner.yudao.template.CodeGenTemplate;
import cn.iocoder.yudao.module.xiaoBizHandler.service.codegen.newInner.GlobalBinding;
import cn.iocoder.yudao.module.xiaoBizHandler.service.codegen.newInner.LocalBinding;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class Convert implements CodeGenTemplate {

    public String getPath(XiaoBizHandlerCodegenTableDO table, List<XiaoBizHandlerCodegenColumnDO> columns, GlobalBinding globalBinding, LocalBinding localBinding, XiaoBizHandlerCodegenColumnDO primaryColumn) {
        PathHandler pathHandler = PathHandler.builder()
                .table(table)
                .columns(columns)
                .globalBinding(globalBinding)
                .localBinding(localBinding)
                .primaryColumn(primaryColumn)
                .build();
        return pathHandler.javaModuleImplMainFilePath("convert/" + table.getBusinessName() + "/" + table.getClassName() + "Convert");
    }


    public String render(XiaoBizHandlerCodegenTableDO table, List<XiaoBizHandlerCodegenColumnDO> columns, GlobalBinding globalBinding, LocalBinding localBinding, XiaoBizHandlerCodegenColumnDO primaryColumn) {
        StringBuilderHandler code = new StringBuilderHandler();
        code.apAndBl("package " + globalBinding.getBasePackage() + ".module." + table.getModuleName() + ".convert." + table.getBusinessName() + ";");
        code.bl();
        code.apAndBl("import java.util.*;");
        code.bl();
        code.apAndBl("import " + globalBinding.getPageResultClassName() + ";");
        code.bl();
        code.apAndBl("import org.mapstruct.Mapper;");
        code.apAndBl("import org.mapstruct.factory.Mappers;");
        code.apAndBl("import " + globalBinding.getBasePackage() + ".module." + table.getModuleName() + ".controller." + localBinding.getSceneEnum().getBasePackage() + "." + table.getBusinessName() + ".vo.*;");
        code.apAndBl("import " + globalBinding.getBasePackage() + ".module." + table.getModuleName() + ".dal.dataobject." + table.getBusinessName() + "." + table.getClassName() + "DO;");
        code.bl();
        code.apAndBl("/**");
        code.apAndBl(" * " + table.getClassComment() + " Convert");
        code.apAndBl(" *");
        code.apAndBl(" * @author " + table.getAuthor() + "");
        code.apAndBl(" */");
        code.apAndBl("@Mapper");
        code.apAndBl("public interface " + table.getClassName() + "Convert {");
        code.bl();
        code.apAndBl("    " + table.getClassName() + "Convert INSTANCE = Mappers.getMapper(" + table.getClassName() + "Convert.class);");
        code.bl();
        code.apAndBl("    " + table.getClassName() + "DO convert(" + localBinding.getSceneEnum().getPrefixClass() + "" + table.getClassName() + "CreateReqVO bean);");
        code.bl();
        code.apAndBl("    " + table.getClassName() + "DO convert(" + localBinding.getSceneEnum().getPrefixClass() + "" + table.getClassName() + "UpdateReqVO bean);");
        code.bl();
        code.apAndBl("    " + localBinding.getSceneEnum().getPrefixClass() + "" + table.getClassName() + "RespVO convert(" + table.getClassName() + "DO bean);");
        code.bl();
        code.apAndBl("    List<" + localBinding.getSceneEnum().getPrefixClass() + "" + table.getClassName() + "RespVO> convertList(List<" + table.getClassName() + "DO> list);");
        code.bl();
        code.apAndBl("    PageResult<" + localBinding.getSceneEnum().getPrefixClass() + "" + table.getClassName() + "RespVO> convertPage(PageResult<" + table.getClassName() + "DO> page);");
        code.bl();
        code.apAndBl("    List<" + localBinding.getSceneEnum().getPrefixClass() + "" + table.getClassName() + "ExcelVO> convertList02(List<" + table.getClassName() + "DO> list);");
        code.bl();
        code.apAndBl("}");
        code.bl();
        return code.toString();
    }

}